package org.lgiavedoni.android.franq.core.contact;

import java.util.ArrayList;
import java.util.List;

import lombok.Data;

import org.lgiavedoni.android.franq.core.contact.ContactPhone.PhoneType;

@Data
public class Contact {

	private String name;
	private String mail;
	private final List<ContactPhone> phones = new ArrayList<ContactPhone>();

	public void addPhone(ContactPhone cPhone) {
		phones.add(cPhone);
	}

	public void addPhone(String number, PhoneType type) {
		phones.add(new ContactPhone(number, type));
	}

	public void addPhone(String number, int type) {
		phones.add(new ContactPhone(number, type));
	}

	public ContactPhone getSMSPhone() {
		// First try to find the mobile phone
		for (ContactPhone cPhone : phones) {
			if (cPhone.getType().equals(PhoneType.TYPE_MOBILE))
				return cPhone;
		}
		// mmm, return the first
		return phones.size() > 0 ? phones.get(0) : null;
	}

	@Override
	public String toString() {
		return name;
	}

	public boolean hasPhone() {
		return phones == null || phones.size() == 0 ? false : true;
	}
	
	public boolean isJustMail(){
		if(name.trim().indexOf("@")!=-1 && name.trim().indexOf(" ")==-1 && phones.size()==0)
			return true;
		else
			return false;
	}

}
